using NUnit.Framework;
using wpffc.contracts.domaindata;
using wpffc.contracts.infrastructure;
using wpffc.flashcardbox.domaindata;

namespace wpffc.flashcardbox.tests.integration
{
    [TestFixture]
    public class test_Learn
    {
        private Learn _sut;
        private SharedState<IFlashCardBox> _boxContainer;


        [SetUp]
        public void Initialize()
        {
            // Build
            _boxContainer = new SharedState<IFlashCardBox>();

            var adv = new Advance_card();
            var refill = new Refill_batch();
            var next = new Get_next_card();
            _sut = new Learn(adv, refill, next);

            // Inject
            adv.Inject(_boxContainer);
            next.Inject(_boxContainer);
        }


        [Test]
        public void Moving_cards()
        {
            var box = new FlashCardBox(1, 2, new[] { 0, 1 });

            box.Batch.Enqueue(new BatchCard { CompartmentIndex = 1, Card = new Card { Question = "Q1", Answer = "A1" } });

            _boxContainer.Value = box;
            Card nextCard = null;
            _sut.NextCardToLearn += _ => nextCard = _;

            _sut.Start_learning(box);

            _sut.Process_answer(true);

            Assert.AreEqual(1, box.Archive.Count);
            Assert.AreEqual("[Congratulations!]", nextCard.Question);
        }
    }
}